package mysql

import (
	"errors"
)

type Log struct {
	Id         uint `gorm:"column:id;primary_key" json:"id" form:"id"`
	Status     int  `gorm:"column:status" json:"status" form:"status"`
	Deleted    int  `gorm:"column:deleted" json:"deleted"`
	AddTime    int32 `gorm:"column:add_time" json:"add_time"`
	UpdateTime int32 `gorm:"column:update_time" json:"update_time"`
	Memo       string `gorm:"column:memo" json:"memo" form:"memo"`
	IdAdmin uint `gorm:"column:id_admin" json:"id_admin"`
	Name string  `gorm:"column:name" json:"name"`
	Url string   `gorm:"column:url" json:"url"`
	Text string  `gorm:"column:text" json:"text"`
	Ip string    `gorm:"column:ip" json:"ip"`
	Param string `gorm:"column:param" json:"param"`

}

//这一步的意思是改表明的  默认表明是带s的
func (Log) TableName() string {
	return "k_admin_operat_log"
}

func (l Log) GetList(where []map[string]interface{},page int,pageSize int) (map[string]interface{},error){

	if page <= 0 {
		return nil,errors.New("page 不正确")
	}
	if page == 1 {
		page = 0
	}
	result := map[string]interface{}{}
	db :=Db
	num := 0
	log1 := []Log{}
	offset := (page-1)*pageSize


	for _, m := range where {
		db = db.Where(m["filed"].(string)+" "+m["exp"].(string)+" ?",m["val"])
	}

	err := db.Model(&Log{}).Count(&num).Limit(pageSize).Offset(offset).Find(&log1).Error
	if err == nil{
		result["data"] = log1
		result["count"] = num
	}
    return result,err;

}